const moment = require("moment");
module.exports = (sequelize, DataTypes) => {
    return sequelize.define('article', {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            allowNull: false,
            autoIncrement: true
        },

        title: {
            type: DataTypes.STRING,
            allowNull: false,
            field: "title"
        },
        author: {
            type: DataTypes.STRING,
            allowNull: false,
            field: "author"
        },
        content: {
            type: DataTypes.STRING,
            allowNull: false,
            field: "content"
        },
        category: {
            type: DataTypes.TEXT,
            allowNull: false,
            field: "category",
        },
        createAt: {
            type: DataTypes.DATE,
            get() {
                return moment(this.getDataValue("createAt").format("YYYY-MM-DD HH:mm:ss"));
            }
        },
        updatedAt: {
            type: DataTypes.DATE,
            get() {
                return moment(this.getDataValue("updateAt").format("YYYY-MM-DD HH:mm:ss"));
            },
            freezeTableName: true
        },

    })
}